package com.app.controller;

import com.app.model.*;
import com.app.service.*;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.app.vo.*;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.app.service.impl.PersonServiceImpl.getCurrentDateOfYear;

@RestController
@Controller
@RequestMapping("/api/home")
public class HomeController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private TypeService typeService;
    @Autowired
    private PersonService personService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ComputerService computerService;
    @Autowired
    private IncidentService incidentService;
    @Autowired
    private ProtectionPointService protectionPointService;
    @Autowired
    private PlantService plantService;
    @Autowired
    private TestsService testsService;
    @Autowired
    private ElectronicService electronicService;
    @Autowired
    private AttachmentService attachmentService;
    @Autowired
    private PersonCheckService personCheckService;
    @Autowired
    private PersonTrainService personTrainService;

    /**
     * 政治面貌饼图统计
     *
     * @param request
     * @return
     */
    @GetMapping("/zzmmPieCount")
    public Result<Object> zzmmPieCount(HttpServletRequest request) {
//         校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.zzmmPieCount();
        return Result.success(voList);
    }

    /**
     * 学历饼图统计
     *
     * @param request
     * @return
     */
    @GetMapping("/educationTextPieCount")
    public Result<Object> educationTextPieCount(HttpServletRequest request) {
        // 校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.educationTextPieCount();
        return Result.success(voList);
    }

    /**
     * 干部衔级饼图统计
     *
     * @param request
     * @return
     */
    @GetMapping("/officerPieCount")
    public Result<Object> genderPieCount(HttpServletRequest request) {
        // 校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.officerPieCount();
        return Result.success(voList);
    }

    /**
     * 战士衔级饼状图
     * @param request
     * @return
     */
    @GetMapping("/soldierRankTitlePieCount")
    public Result<Object> rankTitlePieCount(HttpServletRequest request) {
        // 校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.rankTitlePieCount();
        return Result.success(voList);
    }

    /**
     * 人员类型饼状图
     *
     * @param request
     * @return
     */
    @GetMapping("/personTypePieCount")
    public Result<Object> personTypePieCount(HttpServletRequest request) {
        // 校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.personTypePieCount();
        return Result.success(voList);
    }

    /**
     * 教育水平
     * @param request
     * @return
     */
    @GetMapping("/positionLevel")
    public Result<Object> positionLevelPieCount(HttpServletRequest request) {
//         校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = personService.positionLevelPieCount();
        return Result.success(voList);
    }

    @GetMapping("/plantPieCount")//厂房饼图数量统计
    public Result<Object> plantPieCount(HttpServletRequest request) {
        //         校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = plantService.plantPieCount();
        return Result.success(voList);
    }

    @GetMapping("/electronicPieCount")//电子设备类型饼图数量统计
    public Result<Object> electronicPieCount(HttpServletRequest request) {
        //         校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<NameAndValueVo> voList = electronicService.electronicPieCount();
        return Result.success(voList);
    }

    @GetMapping("/homeCount")//顶部数量统计
    public Result<Object> homeCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        Integer depCount = departmentService.DepartmentCount(depIdList);//部门数量
        Integer personCount = personService.PersonCount(depIdList);//人员数量
        List<PersonModel> personList = personService.otherPersonList(depIdList);
        Integer electronicCount = personList.size();//个人电子设备
        Integer comCount = computerService.comCount(depIdList);//办公计算机数量
        Integer incCount = 0;
//                incidentService.incidentCount();//事件数量  无部门ID
        Integer proCount = protectionPointService.proCount(depIdList);//保护点数量
        Integer plantCount = plantService.plantCount(depIdList);//技术阵地/厂房数量
        Integer typeCount = typeService.typeCount(depIdList);//型号数量
        Integer testsCount = testsService.testCount(depIdList);//实验数量
        Integer attCount = attachmentService.count();
//        CategoryModel categoryModel = categoryService.HomeCount();
        HomeCountVo vo = new HomeCountVo();
        vo.setDepCount(depCount);
        vo.setPersonCount(personCount);
        vo.setElectronicCount(electronicCount);
        vo.setComCount(comCount);
        vo.setIncCount(incCount);
        vo.setProCount(proCount);
        vo.setPlantCount(plantCount);
        vo.setTypeCount(typeCount);
        vo.setTestsCount(testsCount);
        vo.setAttCount(attCount);
        return Result.success(vo);
    }


    @GetMapping("/pieCount")//人员饼图数量统计
    public Result<Object> pieCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<PersonModel> personList1 = personService.getStatisticsByIds(depIdList, "gender");
        PersonModel personModel = new PersonModel();
        List<IndexVo> voList1 = new ArrayList<>();
        for (int i = 0; i < personList1.size(); i++) {
            IndexVo vo = new IndexVo();
            String gender = "";
            vo.setName(gender);
            vo.setValue(personList1.get(i).getCount());
            voList1.add(vo);
        }
        personModel.setGenderList(voList1);

        List<PersonModel> personList2 = personService.getStatisticsByIds(depIdList, "zzmm");
        List<IndexVo> voList2 = new ArrayList<>();
        for (int i = 0; i < personList2.size(); i++) {
            IndexVo vo = new IndexVo();
            String zzmmText = "";
            List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(10);//政治面貌
            for (int j = 0; j < categoryModelList.size(); j++) {
                if (categoryModelList.get(j).getId().equals(personList2.get(i).getZzmm())) {
                    zzmmText = categoryModelList.get(j).getName();
                }
                vo.setName(zzmmText);
                vo.setValue(personList2.get(i).getCount());
            }
            voList2.add(vo);
        }
        personModel.setZzmmList(voList2);

        List<PersonModel> personList3 = personService.getStatisticsByIds(depIdList, "person_type");
        List<IndexVo> voList3 = new ArrayList<>();
        for (int i = 0; i < personList3.size(); i++) {
            IndexVo vo = new IndexVo();
            String personTypeText = "";
            List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(11);//人员类型
            for (int j = 0; j < categoryModelList.size(); j++) {
                if (categoryModelList.get(j).getId().equals(personList3.get(i).getPersonType())) {
                    personTypeText = categoryModelList.get(j).getName();
                }
                vo.setName(personTypeText);
                vo.setValue(personList3.get(i).getCount());
            }
            voList3.add(vo);
        }
        personModel.setPersonTypeList(voList3);

        List<PersonModel> personList4 = personService.getStatisticsByIds(depIdList, "position_level");
        List<IndexVo> voList4 = new ArrayList<>();
        for (int i = 0; i < personList4.size(); i++) {
            IndexVo vo = new IndexVo();
            vo.setName(personList4.get(i).getPositionLevel());
            vo.setValue(personList4.get(i).getCount());
            voList4.add(vo);
        }
        personModel.setPositionLevelList(voList4);

        List<PersonModel> personList5 = personService.getStatisticsByIds(depIdList, "rank_title");
        List<IndexVo> voList5 = new ArrayList<>();

        for (int i = 0; i < personList5.size(); i++) {
            IndexVo vo = new IndexVo();
            vo.setName(personList5.get(i).getRankTitle());
            vo.setValue(personList5.get(i).getCount());
            voList5.add(vo);
        }
        personModel.setRankTitleList(voList5);

        List<PersonModel> personList6 = personService.getStatisticsByIds(depIdList, "education_text");
        List<IndexVo> voList6 = new ArrayList<>();
        for (int i = 0; i < personList6.size(); i++) {
            IndexVo vo = new IndexVo();
            String educationText = "";
            List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(6);//学历
            for (int j = 0; j < categoryModelList.size(); j++) {
                vo.setName(educationText);
                vo.setValue(personList6.get(i).getCount());
            }
            voList6.add(vo);
        }
        personModel.setEducationList(voList6);
        return Result.success(personModel);

    }



    @GetMapping("/pointPieCount")//保护点饼图数量统计
    public Result<Object> pointPieCount(HttpServletRequest request) {
        //         校验token并获取用户信息
        AdminUserModel user = validateTokenAndGetUser(request);
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<ProtectionPointModel> pointModelList = protectionPointService.getStatisticsByIds(depIdList, "type");
        List<IndexVo> voList = new ArrayList<>();
        for (int i = 0; i < pointModelList.size(); i++) {
            IndexVo vo = new IndexVo();
            String typeText = "";
            List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(89);
            for (int j = 0; j < categoryModelList.size(); j++) {
                vo.setName(typeText);
                vo.setValue(pointModelList.get(i).getCount());
            }
            voList.add(vo);
        }
        return Result.success(voList);
    }



    @GetMapping("/typePieCount")//型号饼图数量统计
    public Result<Object> typePieCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<TypeModel> typeList = typeService.getTypeList(depIdList);
        List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(26);
        List<IndexVo> voList = new ArrayList<>();
        for (int i = 0; i < categoryModelList.size(); i++) {
            IndexVo vo = new IndexVo();
            String typeText = "";
            Integer num = 0;
//            for (int i1 = 0; i1 < typeList.size(); i1++) {
//                if (categoryModelList.get(i).getId().equals(typeList.get(i1).getType())) {
//                    typeText = categoryModelList.get(i).getName();
//                    num += typeList.get(i1).getNums();
//                }
//            }
            vo.setName(typeText);
            vo.setValue(num);
            voList.add(vo);
        }
        return Result.success(voList);
    }

    @GetMapping("/testPieCount")//实验饼图数量统计
    public Result<Object> testPieCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<TypeModel> typeList = typeService.getTypeList(depIdList);
        List<IndexVo> voList = new ArrayList<>();
        for (int i = 0; i < typeList.size(); i++) {
            IndexVo vo = new IndexVo();
            List<TestsModel> testsModelList = testsService.getTestByType(typeList.get(i).getId());
            if (testsModelList != null && testsModelList.size() > 0) {
                vo.setName(typeList.get(i).getName());
                vo.setValue(testsModelList.size());
            }
            voList.add(vo);
        }
        return Result.success(voList);
    }

    @GetMapping("/attachmentPostCount")//训练教材柱状图数量统计
    public Result<Object> attachmentPostCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<AttachmentModel> attList = attachmentService.getStatisticsByIds(depIdList, "pid");
        List<Integer> pidList = new ArrayList<>();
        pidList.add(10);
        pidList.add(11);
        pidList.add(12);
        List<AttachmentModel> resultList = null; // list根据某个key筛选出指定数据
        resultList = attList.stream().filter((AttachmentModel a) -> pidList.contains(a.getPid()))
                .collect(Collectors.toList());

        List<IndexVo> voList = new ArrayList<>();
        for (int i = 0; i < resultList.size(); i++) {
            IndexVo vo = new IndexVo();
            String pidText = "";
            if (resultList.get(i).getPid() == 10) {
                pidText = "基础训练";
            } else if (resultList.get(i).getPid() == 11) {
                pidText = "专业技术训练";
            } else if (resultList.get(i).getPid() == 12) {
                pidText = "体能训练";
            }
            vo.setName(pidText);
            vo.setValue(resultList.get(i).getCount());
            voList.add(vo);
        }
        return Result.success(voList);
    }

    @GetMapping("/checkPostCount")//人员年度考核柱状图数量统计
    public Result<Object> checkPostCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<PersonModel> personList = personService.otherPersonList(depIdList);
        List<Integer> personIdList = new ArrayList<>();
        for (int i = 0; i < personList.size(); i++) {
            personIdList.add(personList.get(i).getId());
        }
        String year = getCurrentDateOfYear();
        Integer intYear = Integer.parseInt(year);
        List<String> yearList = getYearList(4);
        List<Integer> intList = yearList.stream().map(Integer::parseInt).collect(Collectors.toList());
        List<PersonCheckModel> checkModelList = personCheckService.getPersonByDepAndYear(personIdList, yearList);
        Map<String, int[]> map = new HashMap<>();

        List<CheckPostVo> checkPostVoList = new ArrayList<>();

        for (int i = 0; i < intList.size(); i++) {
            int[] arr = new int[4];
            int countA = 0;
            int countB = 0;
            int countC = 0;
            int countD = 0;
            for (int i1 = 0; i1 < checkModelList.size(); i1++) {
                if (intList.get(i).equals(checkModelList.get(i1).getYear())) {
                    if (checkModelList.get(i1).getCheckResult() == 39) {
                        countA += 1;
                    }
                    if (checkModelList.get(i1).getCheckResult() == 40) {
                        countB += 1;
                    }
                    if (checkModelList.get(i1).getCheckResult() == 41) {
                        countC += 1;
                    }
                    if (checkModelList.get(i1).getCheckResult() == 42) {
                        countD += 1;
                    }
                    arr[0] = countA;
                    arr[1] = countB;
                    arr[2] = countC;
                    arr[3] = countD;
                }
            }
            map.put(intList.get(i).toString(), arr);
        }

        return Result.success(map);
    }

    @GetMapping("/testPostCount")//年度实验考核柱状图数量统计
    public Result<Object> testPostCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        String year = getCurrentDateOfYear();
        Integer intYear = Integer.parseInt(year);
        List<String> yearList = getYearList(5);
        List<Integer> intList = yearList.stream().map(Integer::parseInt).collect(Collectors.toList());

        Integer[] yearArr = new Integer[5];
        for (int i = 0; i < yearArr.length; i++) {
            yearArr[i] = intList.get(i);
        }
        Map<Integer, Integer> map = new HashMap<>();
        List<TestsModel> testsModelList = testsService.getStatisticsByIds(depIdList, intList, "year");//取出该部门近五年的实验
        for (int i = 0; i < yearArr.length; i++) {
            for (int j = 0; j < testsModelList.size(); j++) {
                if (yearArr[i].equals(testsModelList.get(j).getYear())) {
                    if (testsModelList.get(j).getCount() != null) {
                        map.put(yearArr[i], testsModelList.get(j).getCount());
                        break;
                    } else {
                        map.put(yearArr[i], 0);
                    }
                } else {
                    map.put(yearArr[i], 0);
                }
            }
        }
        return Result.success(map);
    }

    @GetMapping("/typePostCount")//各型号试验数统计
    public Result<Object> typePostCount(Integer year,
                                        HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<TypeModel> typeModelList = typeService.typeListByDepId(depIdList);//根据传进来的部门ID取所有型号
        List<Integer> typeIdList = new ArrayList<>();//取到所有型号的ID
        for (int i = 0; i < typeModelList.size(); i++) {
            typeIdList.add(typeModelList.get(i).getId());
        }
        Map<String, Integer> map = new HashMap<>();

        List<TestsModel> testsModelList = testsService.getTestByIds(typeIdList, "model_type", year);//取出该部门传进来型号ID的实验
        for (int i = 0; i < typeModelList.size(); i++) {
            for (int j = 0; j < testsModelList.size(); j++) {
                if (typeModelList.get(i).getId().equals(testsModelList.get(j).getModelType())) {
                    if (testsModelList.get(j).getCount() != null) {
                        map.put(typeModelList.get(i).getName(), testsModelList.get(j).getCount());
                        break;
                    } else {
                        map.put(typeModelList.get(i).getName(), 0);
                    }
                } else {
                    map.put(typeModelList.get(i).getName(), 0);
                }
            }
        }
        return Result.success(map);
    }

    @GetMapping("/trainPostCount")//人员军事训练柱状图数量统计
    public Result<Object> trainPostCount(
            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        List<Integer> depIdList = departmentService.getDepId(user.getDepartmentId());//当前部门以及下级本门ID
        List<PersonModel> personList = personService.otherPersonList(depIdList);//取部门以及下级部门的人员id
        List<Integer> personIdList = new ArrayList<>();
        TrainPostVo voModel = new TrainPostVo();
        for (int i = 0; i < personList.size(); i++) {
            personIdList.add(personList.get(i).getId());
        }
        NumberFormat num = NumberFormat.getPercentInstance();//double转百分比

        List<PersonTrainModel> trainModelList = personTrainService.getTrainByPerson(personIdList);//根据传进来人的id取出来的list
        List<CategoryModel> categoryModelList = categoryService.getCategoryByPid(53);//取训练项目

        Map<String, String[]> map = new HashMap<>();
        for (int i = 0; i < categoryModelList.size(); i++) {
            Integer countA = 0;
            Integer countB = 0;
            Double countC = 0.0;
            for (int j = 0; j < trainModelList.size(); j++) {
                if (categoryModelList.get(i).getId().equals(trainModelList.get(j).getTrainObject())) {
                    List<PersonTrainModel> trainList = personTrainService.trainList(trainModelList.get(j).getTrainObject());
                    for (int k = 0; k < trainList.size(); k++) {
                        if (trainList.get(k).getTrainLevel() == 51) {
                            countA += 1;
                        } else {
                            countB += 1;
                        }
                    }
                    countC = Double.valueOf(Chufa(countA, trainList.size()));
                    String rates = num.format(countC);
                    String[] count = {String.valueOf(countA), String.valueOf(countB), rates};
                    map.put(categoryModelList.get(i).getName(), count);
                    break;
                } else {
                    String[] count = {"0", "0", "0%"};
                    map.put(categoryModelList.get(i).getName(), count);
                }
            }
        }
        return Result.success(map);
    }

    /**
     * 获取近 几年的 年份列表  2021/04/30 Howe
     *
     * @param numYear 几年
     * @return
     */
    public List<String> getYearList(int numYear) {
        List<String> myList = new ArrayList<>();
        String currYear = getCurrentDateOfYear();
        if (!TextUtils.isEmpty(currYear)) {
            int currYear_int = Integer.parseInt(currYear);
//            currYear_int = currYear_int - 1;
            myList.add("" + currYear_int);
            for (int i = 0; i < numYear - 1; i++) {
                currYear_int--;
                myList.add("" + currYear_int);
            }
        }
        return myList;
    }

    public List<String> getYearList1(int numYear) {
        List<String> myList = new ArrayList<>();
//        String currYear = getCurrentDateOfYear();
//        if(!TextUtils.isEmpty(currYear)){
//            int currYear_int = Integer.parseInt(numYear);
//            myList.add(""+currYear_int);
        for (int i = 0; i < 5; i++) {
            numYear -= 1;
            myList.add("" + numYear);
        }
        return myList;
    }

    public static String Chufa(int a, int b) {
        DecimalFormat dF = new DecimalFormat("0.00");
        return dF.format((float) a / b);
    }


    // 校验token并获取用户信息的方法
    private AdminUserModel validateTokenAndGetUser(HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            throw new IllegalArgumentException("token不存在");
        }
        String userId = TokenUtils.verify(token);
        return adminUserService.getUserByUserId(Integer.parseInt(userId));
    }
}
